package thread;

/**
 * @author DBX
 * @effect java中所有的代码都是靠线程运行的，main也不列外
 *
 *          static Thread currentThread()
 *          线程提供了静态方法currentThread可以获取运行该方法的线程
 * @date 2021/8/31 0031 - 14:33
 */
public class CurrentThreadDemo {
    public static void main(String[] args) {
        Thread main = Thread.currentThread();
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                Thread t = Thread.currentThread();
                System.out.println("自定义线程："+t);
                doSome();
                System.out.println("自定义线程执行完毕！");
            }
        });
        t.start();
        System.out.println("主线程："+main);
        doSome();
        System.out.println("主线程结束");
    }
    public static void doSome(){
        for (int i = 0; i < 100; i++) {
            System.out.println(">>>>>"+Thread.currentThread());
        }
    }
}
